require(['monitor', 'gaodeMap'], function () {

    $('#monitor').monitor({
        canId: '12',
        callback: function (data) {
        	loadData(data);
        },
        clearData: function () {
        	loadData({});
        }
    });
    
    $('#iCenter').css({
		width : $(window).width() - 655,
		height : 482
	});
 
	// 高德地图对象
	var bus=null;	
	var map = new MapGaoDe(107.49023438,36.24427318, 2);
	
	function loadData(data) {
		if(!$.isEmptyObject(data)){
			//经纬度
			if (data.longitude && data.latitude) {
				if (bus) {
					bus.clear();
				}
				map.setMapLevel(14);
				bus = new Bus(map, '', data.longitude, data.latitude);
				bus.setDirection(data.direction);
				bus.show();
				map.mapMoveTo(data.longitude, data.latitude);
			}
			// 车速
			var chart = $('#speed-chartTS').highcharts(), point = chart.series[0].points[0];

			var speedVal = data.speedOfAMotorVehicle || 0;
			point.update(speedVal);
			$('#speed-textTS').text(speedVal);

			// 转速
			var rpmChart = $('#rpm-chartTS').highcharts(), rmpPoint = rpmChart.series[0].points[0];
			var rpmVal = (data.electricMachineryRotateSpeed || 0) ;
			rmpPoint.update(rpmVal/100);
			$('#rpm-textTS').text(rpmVal/100);
			// 电机电压
			var bvcChart = $('#djdy-chartTS').highcharts(), bvcPoint = bvcChart.series[0].points[0];

			var bvcVal = Number((data.electricMachineryControllerBusBarVoltage || 0).toFixed(1));
			if (bvcVal < 0) {
				bvcVal = 0;
			} else if (bvcVal > 400) {
				bvcVal = 400;
			}
			bvcPoint.update(bvcVal);
			$('#djdy-textTS').text(bvcVal);

			// 电机电流
			var bccChart = $('#djdl-chartTS').highcharts(), bccPoint = bccChart.series[0].points[0];
			var bccVal = Number((data.electricMachineryControllerBusBarElectricCurrent || 0).toFixed(1));
			bccPoint.update(bccVal);
			$('#djdl-textTS').text(bccVal);
			var $state = $('#stateTS');
			var electricMachineryControllerStatus=data.electricMachineryControllerStatus||'111';
			if (electricMachineryControllerStatus== "000") {
				$state.text('READY');
			} else if (electricMachineryControllerStatus== "001") {
				$state.text('RUNNING');
			}
			// 档位gearsStatus
			var gear = data.gears;
			if (gear == '0') {
				$('#gearTS').text('N档');
			} else if (gear == '-1') {
				$('#gearTS').text('R档');
			} else if (gear == '1') {
				$('#gearTS').text('D档');
			}else {
				$('#gearTS').text('-');
			}
			var eltMhyStatus = data.eltMhyStatus;
			if(eltMhyStatus == 0){
				$("#eltMhyStatus").html("电机工作状态:发电");
			}else if(eltMhyStatus == 1){
				$("#eltMhyStatus").html("电机工作状态:驱动");
			}else if(eltMhyStatus == 2){
				$("#eltMhyStatus").html("电机工作状态:停止");
			}else{
				$("#eltMhyStatus").html("电机工作状态:-");
			}
			$("#electricMachineryRotateSpeed").html("电机转速："+(data.electricMachineryRotateSpeed));
			$("#speedOfAMotorVehicle").html("车速："+(data.speedOfAMotorVehicle));
			$("#cluthSt").html(data.cluthSt); //离合器状态
			$("#electricMachineryTemperature").html((data.electricMachineryTemperature));//驱动电机温度(°C)
			$("#electricMachineryControllerBusBarElectricCurrent").html("驱动电流(A)："+(data.electricMachineryControllerBusBarElectricCurrent)/10);
			$("#recoveryCurrent").html("回收电流(A)："+(data.recoveryCurrent  ));
		}
	}

});